#include "param.h"

static volatile FlashParam flashParam;

void SavePara(void)
{
	fram_write((unsigned char*)flashParam.buf, FLASH_PARAM_START_ADDR, FLASH_PARAM_SIZE);
}

void LoadPara(void)
{
	fram_read((unsigned char*)flashParam.buf, FLASH_PARAM_START_ADDR, FLASH_PARAM_SIZE);
}

static volatile FlashParam *ptr_flashparam = 0;
FlashParam* flash_param_get(void)
{
	if(ptr_flashparam == 0)
	{
		LoadPara();
		if(flashParam.param.flag != FLASH_PARAM_INIT_FLAG)
		{
			flashParam.param.flag = FLASH_PARAM_INIT_FLAG;
			flashParam.param.hourCut = 0;
			flashParam.param.hourPress = 0;
			flashParam.param.dayCut = 0;
			flashParam.param.dayPress = 0;
			flashParam.param.machine = 0;
			flashParam.param.power = 0;
			flashParam.param.net = 0;
			SavePara();
		}
		ptr_flashparam = (FlashParam*)(&flashParam);
	}
	return (FlashParam*)ptr_flashparam;
}
